package excel;

import java.io.File;
import java.util.List;
import java.util.Map;

//import javax.transaction.Transactional;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;

import com.FDaasApplicationSpring;
import com.luculent.conf.Const;
import com.luculent.utils.excelfile.GetExcelData;
import com.luculent.utils.excelfile.GetExcelImg;
import com.luculent.utils.util.FilePathUtil;
 

/**
 *  
 * @author ShiQiang
 *
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes={FDaasApplicationSpring.class})
public class ImportExeclToOrale {
	@Autowired
	JdbcTemplate jdbcTemplate;
	 
	
	@Test
	public void testImport()throws Exception{
		
		List<File> fileList = FilePathUtil.getFileList("F:/扶贫办文件/00000001/文钟/4.11东三眼井");  
		for(File file : fileList){
			Map<String,String> result = null;
			String subPath = "fupinban/img/";  
			String local = Const.ATTACHMENTS_LOCAL_PATH + subPath; 
		
			String xian= "150402000000"	;
			String xiang = "150402003000";
			String cun = "150402003005";
			result = GetExcelData.getInfo(file.getAbsolutePath(),GetExcelImg.getInfo(file.getAbsolutePath(),local),xian,xiang,cun);
			for(String res :result.values()){
				System.out.println("sql:"+res);
				insert(res);
			} 
		}  
	} 
	//@Transactional
	@Rollback(false)
	private void insert(String res){
		jdbcTemplate.update(res);
	}
//	String xian = "红山区";
//	String xiang = "";
//	String cun = "";
//	String sqlxx = "select * from FPB_ADDRESS where NAME like '%"+xian+"%' and levels ='1'";
//	Map<String, Object> xianx = jdbcTemplate.queryForMap(sqlxx);
//	String sqlx = "select * from FPB_ADDRESS where NAME like '%"+xiang+"%' and levels ='2' and pid='"+xianx.get("ID")+"'";
//	Map<String, Object> xiangx = jdbcTemplate.queryForMap(sqlx);
//	String sqlc = "select * from FPB_ADDRESS where NAME like '%"+cun+"%' and levels ='3' and pid='"+xiangx.get("ID")+"'";
//	Map<String, Object> cunx = jdbcTemplate.queryForMap(sqlc);
//	System.out.println(xianx);
//	System.out.println(xiangx);
//	System.out.println(cunx);
}
